//
//  ViewController.m
//  Buiom_7.0
//
//  Created by lanou3g on 15/10/28.
//  Copyright © 2015年 triffe. All rights reserved.
//

#import "ViewController.h"
#import "FilmVC.h"
#import "TourismFirstVC.h"
#import "ShowVC.h"
#import "HomeCell.h"




#import "ShowVC.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,MONActivityIndicatorViewDelegate>
@property (nonatomic, strong) MONActivityIndicatorView *indicatorView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addSubViews];



    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(actionLeftBarButton:)];

    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    
}



- (void)actionLeftBarButton:(UIBarButtonItem *)bar
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CDPMenuViewControllerPushLeft" object:nil];

} 



//添加视图
- (void)addSubViews{
    UITableView *tableV = [[UITableView alloc] initWithFrame:CGRectMake(0,0,kWidth,kHeight) style:(UITableViewStylePlain)];
    tableV.dataSource = self;
    tableV.delegate = self;
    tableV.bounces = NO;
    // 添加动画加载等待
    self.indicatorView = [[MONActivityIndicatorView alloc] init];
    _indicatorView.center = tableV.center;
    CGPoint point = _indicatorView.center;
    point.y = tableV.center.y - 200;
    _indicatorView.center = point;
    _indicatorView.delegate = self;
    [tableV addSubview:_indicatorView];
    [_indicatorView startAnimating];
    [self.view addSubview:tableV];
    

}

#pragma mark -- 添加加载圆圈动画的方法
- (UIColor *)activityIndicatorView:(MONActivityIndicatorView *)activityIndicatorView circleBackgroundColorAtIndex:(NSUInteger)index
{
    if (index == 0) {
        return [UIColor redColor];
    }if (index == 1) {
        return [UIColor magentaColor];
    }if (index == 2) {
        return [UIColor orangeColor];
    }if (index == 3) {
        return [UIColor purpleColor];
    }
    return [UIColor yellowColor];
}



//协议实现方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *indenifier = @"Cell";
    HomeCell *cell = [tableView dequeueReusableCellWithIdentifier:indenifier];
    if (cell == nil) {
        cell = [[HomeCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:indenifier];
    }
    NSArray *array = @[@"smallmovie.jpg",@"fit.jpg",@"smalltravels.jpg"];
    cell.picView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",array[indexPath.row]]];
    
    [_indicatorView stopAnimating];
    
//    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"GIFlangren" ofType:@"gif"];
//    NSData *gif = [NSData dataWithContentsOfFile:filePath];
//    
//    UIWebView *webviewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
//    [webviewBG loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
//    webviewBG.userInteractionEnabled = NO;
//    [self.view addSubview:webviewBG];
//    
//    UIView *filter = [[UIView alloc] initWithFrame:self.view.frame];
//    filter.backgroundColor = [UIColor blackColor];
//    filter.alpha = 0.05;
//    [self.view addSubview:filter];
    
    
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return (kHeight-64)/3;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    

    
    
    
    
    if (indexPath.row == 0) {
        FilmVC *filmVC = [[FilmVC alloc] init];
       
        filmVC.modalPresentationStyle = UIModalPresentationFullScreen;
        filmVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentViewController:filmVC animated:YES completion:nil];
    }else if (indexPath.row == 1){
        ShowVC *shouVC = [[ShowVC alloc] init];
        [self.navigationController pushViewController:shouVC animated:YES];
    }else{
        
        TourismFirstVC *tourismFirstVC = [[TourismFirstVC alloc] init];
        UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:tourismFirstVC];
        [self presentViewController:navC animated:YES completion:nil];

    }

    



}




@end
